package com.sfac.hqyj.springBoot.modules.common.controller;


import com.sfac.hqyj.springBoot.modules.common.entity.ImageType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api")
public class DictionaryController {
    private final static Logger LOGGER =
            LoggerFactory.getLogger(DictionaryController.class);

    private static Map<String, Class> dictionaryMap = new HashMap<String, Class>() {{
        put("imageType", ImageType.class);
    }};

    /**
     * 127.0.0.1/api/dictionary/imageType ---- get
     */
    @GetMapping("/dictionary/{enumName}")
    public List<Object> dictionary(@PathVariable String enumName) {
        try {
            if (dictionaryMap.containsKey(enumName)) {
                Class clazz = dictionaryMap.get(enumName);
                Method method = clazz.getDeclaredMethod("values");
                Object[] result = (Object[]) method.invoke(null);
                return Arrays.asList(result);
            }
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.debug(e.getMessage());
        }
        return null;
    }

}
